


#include "PowderGame.h"
#include "Super_Man.h"
#include <math.h>
#include <new>
#include <string.h>

/*--- management functions ---*/

GameManager::GameManager(Super_Man* hero, const vec2f& s) : Super_Widget(hero, s),
		myUrine(1.f/FLOB_DIVISOR, 1.f){
	lastDt=0;
	pointsInCircle(5.0f, circle);
}
/*--- inheritance ftw ---*/
void GameManager::update(const sf::Input& sfi, float time){
	vec2f mPos(sfi.GetMouseX(), GetSize().y-sfi.GetMouseY());
	mPos/=FLOB_DIVISOR;
	if(sfi.IsMouseButtonDown(sf::Mouse::Left)){
		for(size_t i=0; i<circle.size(); ++i){
			myUrine.setDens((vec2i)(mPos+vec2f(circle[i])),5.f);
			//myUrine.addAcc((vec2i)(mPos+vec2f(circle[i])), 50.f*vec2f(circle[i]));
		}
	}
	step(time);
}
void GameManager::SetSize(const vec2f& s){
	if(s!=GetSize()){
		Super_Widget::SetSize(changeSize(s));
	}
}
void GameManager::AddSize(const vec2f& s){
	if(s.x||s.y){
		Super_Widget::SetSize(changeSize(GetSize()+s));
	}
}
void GameManager::Rotate(float Angle) {}
/*--- drawing methods ---*/
void GameManager::setDrawMode(int dm){ drawMode=dm; }
vec2i GameManager::changeSize(vec2i nSize){
	return myUrine.resize(nSize);
}
/*--- simulation methods ---*/
void GameManager::step(float dt){
	lastDt=dt;
	myUrine.simFlStep(dt);
	myUrine.simPhysStep(dt);
	return;
	myUrine.simVelStep(dt);
	myUrine.simDensStep(dt);
}
/*--- IO helper method(s) ---*/
void GameManager::updateLpos(const vec2i& lp){
	lPos=lp;
}

void GameManager::forceRender(sf::RenderTarget& Target){
	Render(Target);
}

const Flob& GameManager::getUrine() const{
	return myUrine;
}

void GameManager::Render(sf::RenderTarget& Target){
	myHero->flipY(true);
	myUrine.drawSmart();
	myHero->flipY(false);
}






